package com.wat.aop.example2;

import org.aopalliance.aop.Advice;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

import java.lang.reflect.Method;

//资本家增强器
@SuppressWarnings("serial")
public class CapitalistAdvisor extends AbstractPointcutAdvisor {

	@Override
	public Advice getAdvice() {
		return new CapitalistAdvice();
	}

	@Override
	public Pointcut getPointcut() {
		String pattern = "com.mytest.aop.bean.Capitalist.*";
		JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
		pointcut.setPattern(pattern);
		return pointcut;
	}

	static class CapitalistAdvice implements AfterReturningAdvice {
		@Override
		public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
			System.out.println("又是愉快的一天 (*^▽^*) ");
		}
	}
}